Chapter 2, float data type, 5 >cat float5.c #include void printfloat(float); main() { float x; int i; printf("\n Dec Hex +- exp+127 1. fraction\n\n"); x = 1; for (i = 1; i < 124; i++) x = x*2.0; for (i = 125; i < 133; i++) { x = x*2.0; printfloat(x); } printf("\n"); x = 1; for (i = 1; i < 124; i++) x = x/2.0; for (i = 125; i < 155; i++) { x = x/2.0; printfloat(x); } } void printfloat(float x) { unsigned long i; union floatandlong { float asfloat; long aslong; } bits32; bits32.asfloat = x; printf(" %12.5g %8.8x ", bits32.asfloat, bits32.aslong); for (i = 0x80000000ul; i > 0; i>>=1) { if (i == 0x40000000ul) printf(" "); if (i == 0x00400000ul) printf(" "); printf("%c", (i & bits32.aslong ? '1' : '0')); } printf("\n"); } unix> gcc float5.c unix> ./a.out Dec Hex +- exp+127 1. fraction 2.1268e+37 7d800000 0 11111011 00000000000000000000000 4.2535e+37 7e000000 0 11111100 00000000000000000000000 8.5071e+37 7e800000 0 11111101 00000000000000000000000 1.7014e+38 7f000000 0 11111110 00000000000000000000000 inf 7f800000 0 11111111 00000000000000000000000 inf 7f800000 0 11111111 00000000000000000000000 inf 7f800000 0 11111111 00000000000000000000000 inf 7f800000 0 11111111 00000000000000000000000 4.702e-38 01800000 0 00000011 00000000000000000000000 2.351e-38 01000000 0 00000010 00000000000000000000000 1.1755e-38 00800000 0 00000001 00000000000000000000000 5.8775e-39 00400000 0 00000000 10000000000000000000000 2.9387e-39 00200000 0 00000000 01000000000000000000000 1.4694e-39 00100000 0 00000000 00100000000000000000000 7.3468e-40 00080000 0 00000000 00010000000000000000000 3.6734e-40 00040000 0 00000000 00001000000000000000000 1.8367e-40 00020000 0 00000000 00000100000000000000000 9.1835e-41 00010000 0 00000000 00000010000000000000000 4.5918e-41 00008000 0 00000000 00000001000000000000000 2.2959e-41 00004000 0 00000000 00000000100000000000000 1.1479e-41 00002000 0 00000000 00000000010000000000000 5.7397e-42 00001000 0 00000000 00000000001000000000000 2.8699e-42 00000800 0 00000000 00000000000100000000000 1.4349e-42 00000400 0 00000000 00000000000010000000000 7.1746e-43 00000200 0 00000000 00000000000001000000000 3.5873e-43 00000100 0 00000000 00000000000000100000000 1.7937e-43 00000080 0 00000000 00000000000000010000000 8.9683e-44 00000040 0 00000000 00000000000000001000000 4.4842e-44 00000020 0 00000000 00000000000000000100000 2.2421e-44 00000010 0 00000000 00000000000000000010000 1.121e-44 00000008 0 00000000 00000000000000000001000 5.6052e-45 00000004 0 00000000 00000000000000000000100 2.8026e-45 00000002 0 00000000 00000000000000000000010 1.4013e-45 00000001 0 00000000 00000000000000000000001 0 00000000 0 00000000 00000000000000000000000 0 00000000 0 00000000 00000000000000000000000 0 00000000 0 00000000 00000000000000000000000 0 00000000 0 00000000 00000000000000000000000 unix>